//script quick add collapse jQuery

$(document).ready(function(){

	$('.add').click(function(){
	    $(this).next('#add-content').slideToggle();
	    $(this).toggleClass('active'); 

	    if ($(this).hasClass('active')) $(this).find('span').html('&#x25B2;')
	    else $(this).find('span').html('&#x25BC;')
	});

});
// fin script quick add collapse jQuery

function geoCoder() {
	$('#location').autoGeocoder();
};


function timePicker() {
	$('#timepicker').timepicker({
		hourGrid: 4,
		minuteGrid: 10
	});
};


//date picker 1
function datepicker1(){
	// Datepicker
	$('#datepicker').datepicker({
		inline: true
	});
	//hover states on the static widgets
	$('#dialog_link, ul#icons li').hover(
		function() { $(this).addClass('ui-state-hover'); }, 
		function() { $(this).removeClass('ui-state-hover'); }
	);
};

//date picker 2
function datepicker2(){
	// Datepicker
	$('#datepicker2').datepicker({
		inline: true
	});
	//hover states on the static widgets
	$('#dialog_link, ul#icons li').hover(
		function() { $(this).addClass('ui-state-hover'); }, 
		function() { $(this).removeClass('ui-state-hover'); }
	);	
};

function ajout_tache(){
	var objet = window.document.forms['ajout_tache_rapide'].elements['objet'].value;
	window.document.getElementById('id_object').value = objet;

	closeQuickAdd();
};

function closeQuickAdd(){
	//attention : probleme avec le curseur ci dessous - à voir
	$('#add-content').slideToggle();
	$('#add-content').toggleClass('active'); 

	if ($('#add-content').hasClass('active')) $('#add-content').find('span').html('&#x25B2;')
	else $('#add-content').find('span').html('&#x25BC;')
	
	$('#objet').val('');
}

function addAlerte(){

	//ajout de l'alerte
    $('#addAlerte').click(function(){
        var date=$('#datepicker2').val();
        var time=$('#timepicker').val();
        if(date=='' || time==''){
            alert('veuillez rentrer une date et une heure');
        }
        else{
            $('<div id="identifiant" class="grid_16"><label class="grid_4 placement_item">Alerte: </label><div id="placement_item" class="grid_2"><input id="newdate" type="text" name="datealert" size="20" value="'+date+'"/></div><div id="placement_item" class="grid_2"><input id="newtime" type="text" name="timealert" value="'+time+'"/></div><div id="placement_item" class="grid_3"><button id="removeAlerte" type="button" class="removeAlerte"> Supprimer</button></div></div><div class="clear"></div>').appendTo('#nouvelle');
            $('#datepicker2').val('');
            $('#timepicker').val('');
        }
    });
   
   
    //fin ajout alerte
    //suppression d'une alerte
    $('.removeAlerte').live('click', function(){       
        $(this).parent("div").parent("div").remove();   
    });
    //fin suppression alerte

}

function addAlerte(){

		//ajout de l'alerte  

        var date=$('#datepicker2').val();
        var time=$('#timepicker').val();
        if(date=='' || time==''){
            alert('veuillez rentrer une date et une heure');
        }
        else{
            $('<div id="identifiant" class="grid_16"><label class="grid_4 placement_item">Alerte: </label><div id="placement_item" class="grid_2"><input id="newdate" type="text" name="datealert" size="20" value="'+date+'"/></div><div id="placement_item" class="grid_2"><input id="newtime" type="text" name="timealert" value="'+time+'"/></div><div id="placement_item" class="grid_3"><button type="button" class="removeAlerte" onclick="delAlerte(this)"> Supprimer</button></div></div><div class="clear"></div>').appendTo('#nouvelle');
            $('#datepicker2').val('');
            $('#timepicker').val('');
        }    
    	//fin ajout alerte
}

function delAlerte(divEl){
	//suppression d'une alerte
	$(divEl).parent("div").parent("div").remove();
	//fin suppression alerte 
}

function policeTask(){

	$(".fittext").fitText(1.2, { minFontSize: '28px', maxFontSize: '60px' });

}

function boutonAdd_HTML(val){

	if(val=="add"){		
		$('<a href="#/accueil" id="buttonAdd" onclick="add();">')			
			.addClass('button2 task2 view')
			.appendTo("#buttonForm");

		$('<span>')
			.text("Ajouter la tache")
			.appendTo('#buttonAdd');
	}
	if(val=="edit"){
		$('<a href="#/accueil" id="buttonEdit" onclick="edit();">')			
			.addClass('button2')
			.appendTo("#buttonForm");

		$('<span>')
			.text("Éditer la tache")
			.appendTo('#buttonEdit');
	}
}